package work.shyk.kongMonitor.dto.param;

import com.fasterxml.jackson.databind.JsonNode;
import work.shyk.kongMonitor.dto.param.interfaces.QueryObj;
import work.shyk.kongMonitor.dto.param.interfaces.Parser;
import work.shyk.kongMonitor.dto.result.interfaces.ValueReceiver;

import java.util.function.Supplier;

/**
 * description: <br>
 * createTime: 2021/3/24 17:11 <br>
 *
 * @author zzh
 */
public class DefaultAggsQuery extends AbstractAggsQuery {
    public DefaultAggsQuery(String key) {
        super(key);
        setParser(new IntegerValueParser());
    }


    public DefaultAggsQuery(String key, AggsEnums aggsEnums, QueryObj obj) {
        super(key, aggsEnums, obj);
    }

    public DefaultAggsQuery(String key, AggsEnums aggsEnums, QueryObj obj, Parser paser) {
        super(key, aggsEnums, obj, paser);
    }


    @Override
    public ValueReceiver parse(JsonNode jsonNode, Supplier receiverSupplier) {
        ValueReceiver valueReceiver = (ValueReceiver) receiverSupplier.get();
        valueReceiver.receiveValue(key, parser.parse(jsonNode.get(key)));
        return valueReceiver;
    }
}
